export = function (sourceId: string, targetIds: string[], roomName?: string, resourceType: ResourceConstant = RESOURCE_ENERGY): ICreepConfig {
    return {
        prepare: (creep: Creep) => {
            if (!roomName) return;
            const room = Game.rooms[roomName];
            if (!room || creep.room.name != room.name)
                creep.moveTo(new RoomPosition(25, 25, roomName));
        },
        isReady: (creep: Creep) => {
            if (!roomName) return true;
            const room = Game.rooms[roomName];
            return room && creep.room.name == room.name;
        },
        source: (creep: Creep) => {
            if (roomName &&( !Game.rooms[roomName] || creep.room.name != Game.rooms[roomName].name)) {
                creep.moveTo(new RoomPosition(25, 25, roomName));
            }
            let source: Source = Game.getObjectById<Source>(sourceId);
            if (creep.harvest(source) == ERR_NOT_IN_RANGE) creep.moveTo(source)
        },
        // 储存能量
        target: (creep: Creep) => {
            if (_.isEmpty(targetIds)) return;
            for (let i = 0; i < targetIds.length; i++) {
                let targetId: string = targetIds[i];
                let target: any = Game.getObjectById<Structure>(targetId);
                if (target && 'store' in target && target.store.getFreeCapacity(RESOURCE_ENERGY) > 0) {
                    if (creep.transfer(target, resourceType) == ERR_NOT_IN_RANGE) {
                        creep.moveTo(target);
                        return
                    }
                }
            }
        },
        // 状态切换条件
        switch: (creep: Creep) => {
            //身上有能量
            if (creep.store.getCapacity() == null) {
                let source: Source = Game.getObjectById<Source>(sourceId);
                if (creep.harvest(source) == ERR_NOT_IN_RANGE) {
                    creep.moveTo(source);
                    creep.memory.working = false;
                } else creep.memory.working = true;
                return creep.memory.working;
            } else {
                // creep 身上没有能量 && creep 之前的状态为“工作”
                if ('store' in creep && creep.store[resourceType] <= 0 && creep.memory.working) {
                    creep.memory.working = false;
                    creep.say('执行 source 阶段')
                }
                // creep 身上能量满了 && creep 之前的状态为“不工作”
                if ('store' in creep && creep.store[resourceType] >= creep.store.getCapacity() && !creep.memory.working) {
                    creep.memory.working = true;
                    creep.say('执行 target 阶段')
                }
                return creep.memory.working
            }
        }

    }
}